package day06;

import java.util.Random;
import java.util.Scanner;

public class practice {
    public static void main(String[] args) {
        //方法的练习：参数
        say();
        say("wdk");
        say("wdf",45);

        int b = sum(5,6);
        System.out.println(b);
        int m=5,n=6;
        int c = sum(m,n);
        System.out.println(c);

        int[] d = generateArray(5,100);
        System.out.println("数组的长度为："+d.length);
        for (int i=0;i<d.length;i++){
            System.out.println(d[i]);
        }
        int[] e = generateArray(8,20);
        System.out.println("第一个元素的值："+e[0]);
        for(int i=0;i<e.length;i++){
            System.out.println(e[i]);

            double[] scores = inputData(6);
            double avg = calAvg(scores);
            System.out.println("平均分："+avg);

        }


        //猜数字小游戏
        Scanner scan = new Scanner(System.in);
        Random rand = new Random();
        int num = rand.nextInt(1000)+1;
        System.out.println(num);

        while (true){
            System.out.println("猜吧！");
            int guess = scan.nextInt();
            if(guess>num){
                System.out.println("猜大了");
            }else if(guess<num){
                System.out.println("猜小了");
            }else {
                System.out.println("猜对了");
                break;
            }
        }

    }
    public static void say(){
        System.out.println("大家好，我叫wkj，今年56岁了");
    }
    public static void say(String name){
        System.out.println("大家好，我叫"+name+"今年32岁了");
    }
    public static void say(String name,int age){
        if(age>=60){
            return;  //结束方法的执行
        }
        System.out.println("大家好，我叫"+name+"今年"+age+"岁了");
    }
    public static int sum(int num1,int num2){
        int num = num1+num2;
        return num;
    }
    public static int[] generateArray(int len,int max){
        Random rand = new Random();
        int[] arr = new int[len];
        for (int i=0;i<arr.length;i++){
            arr[i] = rand.nextInt(max)+1;
        }
        return arr;
    }
    public static double[] inputData(int n){
        double[] scores = new double[n];
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<scores.length;i++){
            System.out.println("请输入第"+(i+1)+"评委的分数");
            scores[i] = scan.nextDouble();
        }
        return scores;
    }
    public static double calAvg(double[] scores){
        double total = 0.0;
        double max = scores[0];
        double min = scores[0];
        for(int i=0;i<scores.length;i++){
            total = total+scores[i];
            if (scores[i]>max){
                max = scores[i];
            }
            if (scores[i]<min){
                min = scores[i];
            }
        }
        double avg = (total-min-max)/(scores.length-2);
        return avg;
    }


}
